﻿using System;
using System.Runtime.InteropServices;
using UnityEngine;
using Valve.VR;

// Token: 0x020005F4 RID: 1524
public class SteamVR_TrackedController : MonoBehaviour
{
	// Token: 0x14000008 RID: 8
	// (add) Token: 0x060026C0 RID: 9920 RVA: 0x000E248C File Offset: 0x000E068C
	// (remove) Token: 0x060026C1 RID: 9921 RVA: 0x000E24C4 File Offset: 0x000E06C4
	public event ClickedEventHandler MenuButtonClicked;

	// Token: 0x14000009 RID: 9
	// (add) Token: 0x060026C2 RID: 9922 RVA: 0x000E24FC File Offset: 0x000E06FC
	// (remove) Token: 0x060026C3 RID: 9923 RVA: 0x000E2534 File Offset: 0x000E0734
	public event ClickedEventHandler MenuButtonUnclicked;

	// Token: 0x1400000A RID: 10
	// (add) Token: 0x060026C4 RID: 9924 RVA: 0x000E256C File Offset: 0x000E076C
	// (remove) Token: 0x060026C5 RID: 9925 RVA: 0x000E25A4 File Offset: 0x000E07A4
	public event ClickedEventHandler TriggerClicked;

	// Token: 0x1400000B RID: 11
	// (add) Token: 0x060026C6 RID: 9926 RVA: 0x000E25DC File Offset: 0x000E07DC
	// (remove) Token: 0x060026C7 RID: 9927 RVA: 0x000E2614 File Offset: 0x000E0814
	public event ClickedEventHandler TriggerUnclicked;

	// Token: 0x1400000C RID: 12
	// (add) Token: 0x060026C8 RID: 9928 RVA: 0x000E264C File Offset: 0x000E084C
	// (remove) Token: 0x060026C9 RID: 9929 RVA: 0x000E2684 File Offset: 0x000E0884
	public event ClickedEventHandler SteamClicked;

	// Token: 0x1400000D RID: 13
	// (add) Token: 0x060026CA RID: 9930 RVA: 0x000E26BC File Offset: 0x000E08BC
	// (remove) Token: 0x060026CB RID: 9931 RVA: 0x000E26F4 File Offset: 0x000E08F4
	public event ClickedEventHandler PadClicked;

	// Token: 0x1400000E RID: 14
	// (add) Token: 0x060026CC RID: 9932 RVA: 0x000E272C File Offset: 0x000E092C
	// (remove) Token: 0x060026CD RID: 9933 RVA: 0x000E2764 File Offset: 0x000E0964
	public event ClickedEventHandler PadUnclicked;

	// Token: 0x1400000F RID: 15
	// (add) Token: 0x060026CE RID: 9934 RVA: 0x000E279C File Offset: 0x000E099C
	// (remove) Token: 0x060026CF RID: 9935 RVA: 0x000E27D4 File Offset: 0x000E09D4
	public event ClickedEventHandler PadTouched;

	// Token: 0x14000010 RID: 16
	// (add) Token: 0x060026D0 RID: 9936 RVA: 0x000E280C File Offset: 0x000E0A0C
	// (remove) Token: 0x060026D1 RID: 9937 RVA: 0x000E2844 File Offset: 0x000E0A44
	public event ClickedEventHandler PadUntouched;

	// Token: 0x14000011 RID: 17
	// (add) Token: 0x060026D2 RID: 9938 RVA: 0x000E287C File Offset: 0x000E0A7C
	// (remove) Token: 0x060026D3 RID: 9939 RVA: 0x000E28B4 File Offset: 0x000E0AB4
	public event ClickedEventHandler Gripped;

	// Token: 0x14000012 RID: 18
	// (add) Token: 0x060026D4 RID: 9940 RVA: 0x000E28EC File Offset: 0x000E0AEC
	// (remove) Token: 0x060026D5 RID: 9941 RVA: 0x000E2924 File Offset: 0x000E0B24
	public event ClickedEventHandler Ungripped;

	// Token: 0x060026D6 RID: 9942 RVA: 0x000E295C File Offset: 0x000E0B5C
	protected virtual void Start()
	{
		if (base.GetComponent<SteamVR_TrackedObject>() == null)
		{
			base.gameObject.AddComponent<SteamVR_TrackedObject>();
		}
		if (this.controllerIndex != 0U)
		{
			base.GetComponent<SteamVR_TrackedObject>().index = (SteamVR_TrackedObject.EIndex)this.controllerIndex;
			if (base.GetComponent<SteamVR_RenderModel>() != null)
			{
				base.GetComponent<SteamVR_RenderModel>().index = (SteamVR_TrackedObject.EIndex)this.controllerIndex;
			}
		}
		else
		{
			this.controllerIndex = (uint)base.GetComponent<SteamVR_TrackedObject>().index;
		}
	}

	// Token: 0x060026D7 RID: 9943 RVA: 0x000E29DC File Offset: 0x000E0BDC
	public void SetDeviceIndex(int index)
	{
		this.controllerIndex = (uint)index;
	}

	// Token: 0x060026D8 RID: 9944 RVA: 0x000E29E8 File Offset: 0x000E0BE8
	public virtual void OnTriggerClicked(ClickedEventArgs e)
	{
		if (this.TriggerClicked != null)
		{
			this.TriggerClicked(this, e);
		}
	}

	// Token: 0x060026D9 RID: 9945 RVA: 0x000E2A04 File Offset: 0x000E0C04
	public virtual void OnTriggerUnclicked(ClickedEventArgs e)
	{
		if (this.TriggerUnclicked != null)
		{
			this.TriggerUnclicked(this, e);
		}
	}

	// Token: 0x060026DA RID: 9946 RVA: 0x000E2A20 File Offset: 0x000E0C20
	public virtual void OnMenuClicked(ClickedEventArgs e)
	{
		if (this.MenuButtonClicked != null)
		{
			this.MenuButtonClicked(this, e);
		}
	}

	// Token: 0x060026DB RID: 9947 RVA: 0x000E2A3C File Offset: 0x000E0C3C
	public virtual void OnMenuUnclicked(ClickedEventArgs e)
	{
		if (this.MenuButtonUnclicked != null)
		{
			this.MenuButtonUnclicked(this, e);
		}
	}

	// Token: 0x060026DC RID: 9948 RVA: 0x000E2A58 File Offset: 0x000E0C58
	public virtual void OnSteamClicked(ClickedEventArgs e)
	{
		if (this.SteamClicked != null)
		{
			this.SteamClicked(this, e);
		}
	}

	// Token: 0x060026DD RID: 9949 RVA: 0x000E2A74 File Offset: 0x000E0C74
	public virtual void OnPadClicked(ClickedEventArgs e)
	{
		if (this.PadClicked != null)
		{
			this.PadClicked(this, e);
		}
	}

	// Token: 0x060026DE RID: 9950 RVA: 0x000E2A90 File Offset: 0x000E0C90
	public virtual void OnPadUnclicked(ClickedEventArgs e)
	{
		if (this.PadUnclicked != null)
		{
			this.PadUnclicked(this, e);
		}
	}

	// Token: 0x060026DF RID: 9951 RVA: 0x000E2AAC File Offset: 0x000E0CAC
	public virtual void OnPadTouched(ClickedEventArgs e)
	{
		if (this.PadTouched != null)
		{
			this.PadTouched(this, e);
		}
	}

	// Token: 0x060026E0 RID: 9952 RVA: 0x000E2AC8 File Offset: 0x000E0CC8
	public virtual void OnPadUntouched(ClickedEventArgs e)
	{
		if (this.PadUntouched != null)
		{
			this.PadUntouched(this, e);
		}
	}

	// Token: 0x060026E1 RID: 9953 RVA: 0x000E2AE4 File Offset: 0x000E0CE4
	public virtual void OnGripped(ClickedEventArgs e)
	{
		if (this.Gripped != null)
		{
			this.Gripped(this, e);
		}
	}

	// Token: 0x060026E2 RID: 9954 RVA: 0x000E2B00 File Offset: 0x000E0D00
	public virtual void OnUngripped(ClickedEventArgs e)
	{
		if (this.Ungripped != null)
		{
			this.Ungripped(this, e);
		}
	}

	// Token: 0x060026E3 RID: 9955 RVA: 0x000E2B1C File Offset: 0x000E0D1C
	protected virtual void Update()
	{
		CVRSystem system = OpenVR.System;
		if (system != null && system.GetControllerState(this.controllerIndex, ref this.controllerState, (uint)Marshal.SizeOf(typeof(VRControllerState_t))))
		{
			ulong num = this.controllerState.ulButtonPressed & 8589934592UL;
			if (num > 0UL && !this.triggerPressed)
			{
				this.triggerPressed = true;
				ClickedEventArgs e;
				e.controllerIndex = this.controllerIndex;
				e.flags = (uint)this.controllerState.ulButtonPressed;
				e.padX = this.controllerState.rAxis0.x;
				e.padY = this.controllerState.rAxis0.y;
				this.OnTriggerClicked(e);
			}
			else if (num == 0UL && this.triggerPressed)
			{
				this.triggerPressed = false;
				ClickedEventArgs e2;
				e2.controllerIndex = this.controllerIndex;
				e2.flags = (uint)this.controllerState.ulButtonPressed;
				e2.padX = this.controllerState.rAxis0.x;
				e2.padY = this.controllerState.rAxis0.y;
				this.OnTriggerUnclicked(e2);
			}
			ulong num2 = this.controllerState.ulButtonPressed & 4UL;
			if (num2 > 0UL && !this.gripped)
			{
				this.gripped = true;
				ClickedEventArgs e3;
				e3.controllerIndex = this.controllerIndex;
				e3.flags = (uint)this.controllerState.ulButtonPressed;
				e3.padX = this.controllerState.rAxis0.x;
				e3.padY = this.controllerState.rAxis0.y;
				this.OnGripped(e3);
			}
			else if (num2 == 0UL && this.gripped)
			{
				this.gripped = false;
				ClickedEventArgs e4;
				e4.controllerIndex = this.controllerIndex;
				e4.flags = (uint)this.controllerState.ulButtonPressed;
				e4.padX = this.controllerState.rAxis0.x;
				e4.padY = this.controllerState.rAxis0.y;
				this.OnUngripped(e4);
			}
			ulong num3 = this.controllerState.ulButtonPressed & 4294967296UL;
			if (num3 > 0UL && !this.padPressed)
			{
				this.padPressed = true;
				ClickedEventArgs e5;
				e5.controllerIndex = this.controllerIndex;
				e5.flags = (uint)this.controllerState.ulButtonPressed;
				e5.padX = this.controllerState.rAxis0.x;
				e5.padY = this.controllerState.rAxis0.y;
				this.OnPadClicked(e5);
			}
			else if (num3 == 0UL && this.padPressed)
			{
				this.padPressed = false;
				ClickedEventArgs e6;
				e6.controllerIndex = this.controllerIndex;
				e6.flags = (uint)this.controllerState.ulButtonPressed;
				e6.padX = this.controllerState.rAxis0.x;
				e6.padY = this.controllerState.rAxis0.y;
				this.OnPadUnclicked(e6);
			}
			ulong num4 = this.controllerState.ulButtonPressed & 2UL;
			if (num4 > 0UL && !this.menuPressed)
			{
				this.menuPressed = true;
				ClickedEventArgs e7;
				e7.controllerIndex = this.controllerIndex;
				e7.flags = (uint)this.controllerState.ulButtonPressed;
				e7.padX = this.controllerState.rAxis0.x;
				e7.padY = this.controllerState.rAxis0.y;
				this.OnMenuClicked(e7);
			}
			else if (num4 == 0UL && this.menuPressed)
			{
				this.menuPressed = false;
				ClickedEventArgs e8;
				e8.controllerIndex = this.controllerIndex;
				e8.flags = (uint)this.controllerState.ulButtonPressed;
				e8.padX = this.controllerState.rAxis0.x;
				e8.padY = this.controllerState.rAxis0.y;
				this.OnMenuUnclicked(e8);
			}
			num3 = (this.controllerState.ulButtonTouched & 4294967296UL);
			if (num3 > 0UL && !this.padTouched)
			{
				this.padTouched = true;
				ClickedEventArgs e9;
				e9.controllerIndex = this.controllerIndex;
				e9.flags = (uint)this.controllerState.ulButtonPressed;
				e9.padX = this.controllerState.rAxis0.x;
				e9.padY = this.controllerState.rAxis0.y;
				this.OnPadTouched(e9);
			}
			else if (num3 == 0UL && this.padTouched)
			{
				this.padTouched = false;
				ClickedEventArgs e10;
				e10.controllerIndex = this.controllerIndex;
				e10.flags = (uint)this.controllerState.ulButtonPressed;
				e10.padX = this.controllerState.rAxis0.x;
				e10.padY = this.controllerState.rAxis0.y;
				this.OnPadUntouched(e10);
			}
		}
	}

	// Token: 0x040026C3 RID: 9923
	public uint controllerIndex;

	// Token: 0x040026C4 RID: 9924
	public VRControllerState_t controllerState;

	// Token: 0x040026C5 RID: 9925
	public bool triggerPressed;

	// Token: 0x040026C6 RID: 9926
	public bool steamPressed;

	// Token: 0x040026C7 RID: 9927
	public bool menuPressed;

	// Token: 0x040026C8 RID: 9928
	public bool padPressed;

	// Token: 0x040026C9 RID: 9929
	public bool padTouched;

	// Token: 0x040026CA RID: 9930
	public bool gripped;
}
